package com.groupseven.happycampus.controller;


import com.groupseven.happycampus.common.pojo.Athletes;
import com.groupseven.happycampus.common.result.LayuiPageVo;
import com.groupseven.happycampus.common.result.R;
import com.groupseven.happycampus.common.vo.BarVo;
import com.groupseven.happycampus.common.vo.PieVo;
import com.groupseven.happycampus.service.AthletesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/athletes")
public class AthletesController {


    @Autowired
    private AthletesService athletesService;


    /**
     * 分页以及模糊查询所有运动员信息
     */

    @RequestMapping("/selectAthletes")
    public LayuiPageVo<Athletes> selectAthletes(@RequestParam Map<String, Object> params) {
        System.out.println(params);
        return athletesService.selectAthletes(params);
    }


    /**
     * 添加运动员信息
     * @param athletes
     * @return
     */

    @RequestMapping("/addAthletes")
    public R addHospital(Athletes athletes) {
        System.out.println(athletes);
        int result = athletesService.addAthletes(athletes);
        if(result==1){
            return R.ok();
        }else{
            return R.error();
        }
    }



    /**
     * 根据id删除运动员信息
     * @param id
     * @return
     */
    @GetMapping("/deleteAthletesById")
    public R deleteAthletesById(Integer id){
        int result = athletesService.deleteAthletesById(id);
        if(result==1){
            return R.ok();
        }else{
            return R.error();
        }
    }



    /**
     * 批量删除运动员信息
     * @param ids
     * @return
     */
    @GetMapping("/deleteAthletesByIds")
    public R deleteAthletesByIds(String ids){
        //根据Id删除学生信息
        int result = athletesService.deleteAthletesByIds(ids);
        if(result>0){
            return R.ok();
        }else{
            return R.error();
        }
    }


    /**
     * 修改运动员信息
     * @param athletes
     * @return
     */

    @RequestMapping("/updateAthletes")
    public R updateAthletes(Athletes athletes){
        System.out.println(athletes);
        int result = athletesService.updateAthletes(athletes);
        if(result==1){
            return R.ok();
        }else{
            return R.error();
        }

    }


    /**
     * 竞赛柱状信息图
     * @return
     */
    @RequestMapping("/sexBar")
    public R projectBar(){
        List<BarVo> list = athletesService.sexBarData();
        return R.ok().data("sexBar",list);
    }




    /**
     * 竞赛项目饼状信息图
     * @return
     */
    @RequestMapping("/sexPie")
    public R projectPie(){
        List<PieVo> list = athletesService.sexPieData();
        return R.ok().data("sexPie",list);
    }

}
